package com.demo.security.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.demo.security.model.Result;

@RestController
public class UserController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @RequestMapping("/login")
    public Result<?> login() {
        return Result.ok("登录成功");
    }

    @RequestMapping("/register")
    public Result<?> register() {
        return Result.ok("用户注册");
    }

    @RequestMapping("/index")
    public Result<?> index() {
        return Result.ok("首页");
    }

    @PreAuthorize("hasRole('USER')")
    @RequestMapping("/addUser")
    public Result<?> addUser() {
        return Result.ok("这是添加用户！！！");
    }

    @RequestMapping("/deleteUser")
    public Result<?> deleteUser() {
        return Result.ok("这是删除用户！！！");
    }

    @PreAuthorize("hasRole('admin')")
    @RequestMapping("/deleteUser1")
    public Result<?> deleteUser1() {
        return Result.ok("这是删除用户1！！！");
    }

    @PreAuthorize("hasAuthority('admin')")
    @RequestMapping("/updateUser")
    public Result<?> updateUser() {
        return Result.ok("这是修改用户！！！");
    }

    @RequestMapping("/findAllUsers")
    public Result<?> findAllUsers() {
        return Result.ok("这是查询用户！！！");
    }

}
